import request from '@/utils/request'

const GOODS_PATH = 'goods'
const PUT_PATH = 'goods/'

const CATE_PATh = 'categories'

import qs from 'querystring'

function getList(params) {
    return request({
        url: GOODS_PATH + '?' + qs.stringify(params),
        method: 'get'
    })
}


// 渲染
function showGoods(obj){
    return request({
        url:GOODS_PATH+'?'+qs.stringify(obj),
        method:"get"
    })
}


// 添加
function addGoods(obj){
    return request({
        url:GOODS_PATH,
        method:"post",
        data:obj
    })
}

// 删除
function delGoods(id){
    return request({
        url:GOODS_PATH+'/'+id,
        method:"delete",
    })
}

// 编辑h回显
function editGoods(id){
    return request({
        url:PUT_PATH+id,
        method:"get"
    })
}

// 级联
function optGoods(params){
    return request({
        url:CATE_PATh+'?'+qs.stringify(params),
        method:"get"
    })
}

// 编辑提交
function putUpdate(id,obj){
    console.log(id,obj);
    return request({
        url:`goods/${id}`,
        method:'put',
        data:obj
    })
}


export {
    showGoods,
    addGoods,
    delGoods,
    editGoods,
    optGoods,
    putUpdate,
    getList
}